package com.sh.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.druid.util.StringUtils;
import com.sh.dao.CustomerDao;
import com.sh.entity.Customer;
import com.sh.entity.User;
import com.sh.service.CustomerService;

@Service()
public class CustomerServiceImpl implements CustomerService{
	@Autowired
	private CustomerDao customerDao;

	@Override
	public List<Customer> listCustomer(Map<String, Object> conMap,User user,String sysTime) {
		// TODO Auto-generated method stub 

		return customerDao.listCustomer(conMap);
	}

	//上传 excel文件,并且到DB
	@Override
	public String saveUpload(List<Customer> checkList, User user, String sysTime) {
		// TODO Auto-generated method stub
		customerDao.saveUpload(checkList,user,sysTime);
		return "";
	}

	//根据用户名查询
	@Override
	public List<Customer> listCustomerByName(Map<String, Object> conMap) {
		// TODO Auto-generated method stub
		return customerDao.listCustomerByName(conMap);
	}
	//批量 删除 客户 信息
	@Override
	public void deleteCustomers(String[] ids) {
		// TODO Auto-generated method stub
		customerDao.deleteCustomers(ids);
	}
	/**
	 * 新增 / 修改 保存数据
	 * */
	@Override
	public void saveCustomers(Customer customer, User user) {
		// TODO Auto-generated method stub
		customerDao.saveCustomers(customer,user);
	}
	//查询数量
	@Override
	public int listCustomerCount(Map<String, Object> conMap, User user, String sysTime) {
		// TODO Auto-generated method stub
		return customerDao.listCustomerCount(conMap);
	}

	//判断 客户名称有么有存在
	@Override
	public boolean isCustomerExist(Customer customer) {
		// TODO Auto-generated method stub
		boolean flag = false;
		//修改的时候判断 客户名称有么有存在
		if(!StringUtils.isEmpty(customer.getId())){
			int count = customerDao.isCustomerExistForUpdate(customer);
			flag = (count==0?false:true);
		}else{
			int count = customerDao.isCustomerExistForAdd(customer);
			flag = (count==0?false:true);
		}

		return flag;
	}
	/**
	 * 分页查询
	 * */
	@Override
	public List<Customer> listCustomerByPage(Map<String, Object> conMap, User user, String sysTime) {
		// TODO Auto-generated method stub
		return customerDao.listCustomerByPage(conMap);
	}




}
